//
//  ChangePwdViewController.m
//  Commerce
//
//  Created by gc on 15/4/1.
//  Copyright (c) 2015年 fei. All rights reserved.
//

#import "ChangePwdViewController.h"

@interface ChangePwdViewController ()

@end

@implementation ChangePwdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navStr = @"修改密码";
    // Do any additional setup after loading the view from its nib.
}

- (IBAction)changeNewPwd:(id)sender{
    if (_oldPwdField.text.length == 0) {
        [SVProgressHUD showInfoWithStatus:@"请输入旧密码"];
        return;
    }else if (_nPwdField.text.length == 0){
        [SVProgressHUD showInfoWithStatus:@"请输入新密码"];
        return;
    }else if (_twoPwdField.text.length == 0){
        [SVProgressHUD showInfoWithStatus:@"请输入确认密码"];
        return;
    }else if (![_twoPwdField.text isEqualToString:_nPwdField.text]){
        [SVProgressHUD showInfoWithStatus:@"两次输入的密码不一致"];
        return;
    }
    
    [SVProgressHUD showWithStatus:@"加载中" maskType:SVProgressHUDMaskTypeBlack];
    //传入的参数
    NSMutableDictionary *parameters = [GlobalData paramterDic];
    NSString *uid = [[GlobalData sharedGlobalData] userinfoDic][@"UserID"];
    [parameters addEntriesFromDictionary:@{@"userid":uid,@"new_pwd":_nPwdField.text,@"old_pwd":_oldPwdField.text}];
    NSLog(@"%@",parameters);
    NSString *url = [NSString stringWithFormat:@"%@user/updatepwd",URL_ROOT];
    
    [[BaseNetwork alloc] initWithMethodUrl:url
                                    params:parameters
                               requestMode:DGHTTPMethodPOST
                               loadingShow:YES
                              didFinshLoad:^(id result) {
                                  id responseObject = result;
                                  [SVProgressHUD dismiss];
                                  if ([responseObject[@"result"] integerValue]==1) {
                                      [SVProgressHUD showSuccessWithStatus:@"修改成功！"];
                                      [self backBtnAct:nil];
                                  }else{
                                      [SVProgressHUD showErrorWithStatus:@"修改失败！"];
                                  }
                                  
                              }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
